package org.flown.shop.entity;


import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.EqualsAndHashCode;


/**
 * 需要配置TypeHandler
 * <typeHandlers>
 *     <typeHandler handler="org.apache.ibatis.type.EnumTypeHandler"/>
 * </typeHandlers>
 * */
@EqualsAndHashCode(callSuper = true)
@Data
public class Orders extends BaseEntity
{
    public enum State
    {
        DEALING,//处理中
        DELIVERED,;//已发货
    }

    @NotNull @Min(1)
    private int goodsID;
    @NotNull @Min(1)
    private int userID;
    @NotNull @Min(1)
    private int sellerID;
    @NotNull @Min(1)
    private int storeID;
    @Min(1)
    private int count;
    @NotNull
    private String address;//地址
    private float price;//订单总价格
    private java.util.Date time = new java.util.Date();//订单时间
    private State state = State.DEALING;//订单状态
    private String trackingNumber;//物流单号
    private java.util.Date deliveryTime;//发货时间


    public Orders() {super();this.count = 1;}
    public Orders(int goods_id, int user_id, int seller_id, int store_id,
                  String address)
    {
        this(goods_id, user_id, seller_id, store_id, address, 1);
    }
    public Orders(int goods_id, int user_id, int seller_id, int store_id,
                  String address, int count)
    {
        this.goodsID = goods_id;
        this.userID = user_id;
        this.sellerID = seller_id;
        this.storeID = store_id;
        this.address = address;
        this.count = count;
    }


    public String asJSONString()
    {
        try {
            return new ObjectMapper().writeValueAsString(this);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
            return null;
        }
    }
}



